package com.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


public class Jsoner {
	
	public String createok(String cd,String json,String msg){
		
		Rsltobj rsltobj=new Rsltobj();Rsltstr rsltstr=new Rsltstr();
		
		String cd_nw=createcode(cd);
		String json_final="";

		try{
			JSONObject job= JSON.parseObject(json);
			rsltobj.setCode(cd_nw);
			rsltobj.setData(job);
			rsltobj.setMsg(msg);
			
			json_final=JSON.toJSONString(rsltobj);
		}catch(Exception e){
			rsltstr.setCode(cd_nw);
			rsltstr.setData(json);
			rsltstr.setMsg(msg);
			
			json_final=JSON.toJSONString(rsltstr);
		}
		
		
		
		
		
		
		return json_final;
		
	
	}
	
	public String createcode(String cd){
		String code="";
		if(cd=="ok"){
			code="A00000";
		}else{
			int asc=0;
			for(int i=0;i<cd.length();i++){
				char c=cd.charAt(i);
				asc=asc+Integer.valueOf(c);
			}
			int bits=String.valueOf(asc).length();
			
			int zeronum=0;
			if(bits<=5){zeronum=5-bits;}

			String zero="";
			for(int i=0;i<zeronum;i++){
				zero=zero+"0";
			}
			code="A"+zero+asc;
		}
		return code;
	}
}
